package com.javafx06.controller;

import com.javafx06.entity.Staff;
import com.javafx06.util.FileUtil;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;

public class StaffUpdateController {

    @FXML
    private TextField name;
    @FXML
    private TextField idcard;
    @FXML
    private ChoiceBox<String> gender;
    @FXML
    private TextField age;
    @FXML
    private TextField zhiwei;
    @FXML
    private DatePicker birthday;
    @FXML
    private TextField depart;
    @FXML
    private DatePicker enterDate;

    private static Staff current;

    public static void setCurrent(Staff current) {
        StaffUpdateController.current = current;
    }

    @FXML
    public void initialize() {
        gender.getItems().clear();
        gender.getItems().addAll("男", "女");

        name.setText(current.getName());
        idcard.setText(current.getIdcard());
        gender.setValue(current.getGender());
        age.setText(current.getAge());
        zhiwei.setText(current.getZhiwei());
        depart.setText(current.getDepart());
        enterDate.getEditor().setText(current.getEnterDate());
        birthday.getEditor().setText(current.getBirthday());
    }

    @FXML
    public void updateDataToFile() {
        Staff staff = new Staff(name.getText(), idcard.getText(), gender.getValue(),
                age.getText(), zhiwei.getText(), birthday.getEditor().getText(), depart.getText(), enterDate.getEditor().getText());
        FileUtil.updateData(staff);
    }

}
